﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Infrastructure.Interfaces;
using Traceability_Management.Read.Api.Application.Command.Processiings_OneWay;
using Traceability_Management.Read.Api.Application.Command.Processiings_TwoWay;

namespace Traceability_Management.Read.Api.Application.CommandHandler.Processiings_TwoWay
{
    public class FirstTwoWayCommandHandler : IRequestHandler<FirstTwoWayCommand, ApiResult<Processiings_Two>>
    {
        IBaseReponsitory<Processiings_Two> Processiings_Two;

        public FirstTwoWayCommandHandler(IBaseReponsitory<Processiings_Two> Processiings_Two)
        {
            this.Processiings_Two = Processiings_Two;
        }

        public async Task<ApiResult<Processiings_Two>> Handle(FirstTwoWayCommand request, CancellationToken cancellationToken)
        {
            var Bachlist = await Processiings_Two.GetQuery().FirstOrDefaultAsync(c => c.Rabit_Batch == request.Batch);
            if (Bachlist != null)
            {
                return new ApiResult<Processiings_Two>
                {
                    Code = ApiEnum.Success,
                    Message = "加载成功了",
                    Data = Bachlist
                };
            }
            else
            {
                return new ApiResult<Processiings_Two>
                {
                    Code = ApiEnum.Success,
                    Message = "请设置信息",
                };
            }
        }
    }
}
